import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../share/my_color.dart';
import 'indicator/round_underline_tab_indicator.dart';


//创建 可滑动的 tabBar，标题导航栏
class TabTitleWidget extends StatelessWidget {
  const TabTitleWidget({
    Key? key,
    this.titleList,
    required TabController? tabController,
    this.isScrollable = true, //是否可以滚蛋， 否--平分
    this.onTop, //title 改变-  分页 改变
    this.indicatorWidth = 16.0, //指示器的宽度
    this.indicatorBottom = 6.0, //指示器距离底部的距离
    this.indicatorHeight = 3.0, //指示器的高度
    this.labelPadding = const EdgeInsets.symmetric(horizontal: 16), //tab padding
    this.padding = const EdgeInsets.symmetric(horizontal: 5), //title导航padding
    this.unSelectLabColor = MyColors.color_85_85_85,
    this.labelColor = MyColors.color_35_35_35,
    this.labelStyle = const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
    this.unSelectLabStyle = const TextStyle(fontSize: 14),
    this.dragStartBehavior = DragStartBehavior.down,
    this.height = 44,
    this.width = double.infinity,
    this.titleWidgetList,
    this.indicatorColor,
  })
      : _tabController = tabController,
        super(key: key);

  final List<String>? titleList;
  final List<Widget>? titleWidgetList;
  final TabController? _tabController;
  final bool isScrollable; //是否可以滑动
  final Function(int value)? onTop;
  final double indicatorWidth;
  final double indicatorBottom;
  final double indicatorHeight;
  final Color? indicatorColor;

  final EdgeInsetsGeometry labelPadding;
  final EdgeInsetsGeometry padding;

  final Color labelColor;
  final TextStyle labelStyle;
  final Color unSelectLabColor;
  final TextStyle unSelectLabStyle;
  final DragStartBehavior dragStartBehavior;
  final double height;
  final double width;


  @override
  Widget build(BuildContext context) {
    return Container(
      padding: padding,
      width: width,
      height: height,
      child: TabBar(
        indicator: RoundUnderlineTabIndicator(
            indicatorWidth: indicatorWidth,
            insets: EdgeInsets.only(bottom: indicatorBottom),
            borderSide: BorderSide(width: indicatorHeight, color:indicatorColor?? Colors.pink)),
        tabs: titleWidgetList!=null ? (
            titleWidgetList!.map((e) => Tab(child: e)).toList()
        ) : (titleList!.map((e) => Tab(text: e)).toList()),
        controller: _tabController,
        isScrollable: isScrollable,
        onTap: (value) {
          if (this.onTop != null) onTop!(value);
        },
        dragStartBehavior: dragStartBehavior,
        labelPadding: labelPadding,
        unselectedLabelColor: unSelectLabColor,
        unselectedLabelStyle: unSelectLabStyle,
        labelColor: labelColor,
        labelStyle: labelStyle,
      ),
    );
  }
}
